﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DLL;

namespace NursingFormSystem.NursingPlanForm
{
    public partial class AddPlanForm : DevExpress.XtraEditors.XtraForm
    {
        string[] user;//当前的登录信息
        string[] patientinfo;
        string inoredit = "";
        string id01 = "";

        //声明一个委托
        public delegate void SuccessUpdateDelegate();
        //声明事件
        public event SuccessUpdateDelegate ShowUpdate;//
        public AddPlanForm(string[] user, string[] patientinfo)
        {
            InitializeComponent();

            dateEdit_date1.Text = DateTime.Now.Date.ToString("yyyy-MM-dd");
            timeEdit_time.EditValue = DateTime.Now.ToShortTimeString().ToString();
            textEdit1.Text = user[1];

            this.patientinfo = patientinfo;
            this.user = user;
            inoredit = "0";//新增页面
        }

        public AddPlanForm(string date, string time, string[] user, string[] patientinfo, string diagnose, string goal, string step, string id)
        {
            InitializeComponent();
            dateEdit_date1.Text = date;
            timeEdit_time.EditValue = time;
            id01 = id;
            textEdit1.Text = user[1];
            memoEdit1.Text = diagnose;
            memoEdit2.Text = goal;
            memoEdit3.Text = step;

            this.patientinfo = patientinfo;
            this.user = user;
            inoredit = "1";//编辑页面
        }
        private void SaveDataInsert()
        {
            string sql = "";
            if (memoEdit1.Text != "" ||
                memoEdit2.Text != "" ||
                memoEdit3.Text != "")
            {
                if (inoredit == "0")
                {
                    sql = "insert into NursingPlanRecord (PatientId,VisitId,PatientName,BedNo,NursingDigagnose,NursingGoal,NursingMeasure,RecordDate,RecordTime,RecordSign,WardName,WardId) values('" + patientinfo[0] + "','" + patientinfo[1] + "','" +
    patientinfo[2] + "','" + patientinfo[5] + "','" + memoEdit1.Text + "','" + memoEdit2.Text + "','" + memoEdit3.Text + "','" + dateEdit_date1.Text + "','" + timeEdit_time.EditValue + "','" + user[1] + "','" + patientinfo[11] + "','" + patientinfo[10] + "');";
                }
                else
                    sql = "update NursingPlanRecord set NursingDigagnose='" + memoEdit1.Text + "',NursingGoal='" + memoEdit2.Text + "', NursingMeasure='" + memoEdit3.Text + "' WHERE PatientId='" + patientinfo[0] + "' AND VisitId='" + patientinfo[1] + "' AND Id='" + id01 + "'";
            }
            if (sql != "")//至少有一条数据
            {
                SqlHelper.ExecuteScalar(System.Data.CommandType.Text, sql, null);
            }
            MessageBox.Show("保存成功！");
            //ShowUpdate();
            this.DialogResult = DialogResult.OK;
        }
        private void simpleButton_cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void simpleButton_save_Click(object sender, EventArgs e)
        {
            SaveDataInsert();
        }
    }
}